#include<iostream>
#include<map>
using namespace std;
map<int, int>mp1, mp2;
int n, x;
bool prime(int x)
{
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) {
			return 0;
		}
	}
	return 1;
}
void fun1(int x)
{
	int m = x;
	for (int i = 2; i < m / 2; i++) {
		while (x % i == 0) {
			mp1[i] = 1;
			x /= i;
		}
	}
}
void fun2(int x)
{
	int m = x;
	for (int i = 2; i < m / 2; i++) {
		while (x % i == 0) {
			mp2[i] = 1;
			x /= i;
		}
	}
}
int main()
{
	scanf("%d", &n);
	bool flag = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (prime(x)) {
			mp1[x] = 1;
			continue;
		}
		fun1(x);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (prime(x)) {
			mp2[x] = 1;
			continue;
		}
		fun2(x);
	}
	for (int i = 2; i <= 1e5; i++) {
		if (mp1[i] == mp2[i]) {
			cout << mp1[i] <<  mp2[i] << endl;
			flag = 1;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}